
package combat.dudes.client.gui.threads.map;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;

import javax.swing.JPanel;

import combat.dudes.client.ClientApp;
import combat.dudes.client.ClientFunctions;
import combat.dudes.client.gui.ClientGUITheme;
import combat.dudes.protocol.data.DoublePoint;
import combat.dudes.protocol.interfaces.ProjectileInt;
import combat.dudes.protocol.interfaces.TrackInt;
import combat.dudes.protocol.interfaces.VehicleInt;


/**
 * @author Laurens Andriessen
 * @version 1.0
 */
public class ClientGUIMap extends JPanel {

	private static final long serialVersionUID = 1L;

	public static enum MapType {
		MAIN, MINI
	};

	private static int i = 0;


	private MapType type;
	private int w;
	private int h;

	public ClientGUIMap(MapType type, int w, int h) {
		this.type = type;
		this.w = w;
		this.h = h;
		this.setBounds(0, 0, w, h);

		this.repaint();
	}

	@Override
	public void paintComponent(Graphics g) {
		Graphics2D g2 = (Graphics2D) g; // Make type Graphics2D
		g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Set AA on
		g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); // Set AA off for text
		g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED); // Set render focus on speed

		g2.setBackground(ClientGUITheme.guiMainMapSea);
		g2.clearRect(0, 0, getWidth(), getHeight());

		// g.setColor(ClientGUITheme.guiMainMapSea); // Sea
		// g.fillRect(0, 0, getWidth(), getHeight());


		i++;

		GUIMapVehicle vehicleImg = null;
		GUIMapProjectile projectileImg = null;
		GUIMapTrack trackImg = null;

		try {
			// Vehicles
			for(VehicleInt vehicle : ClientApp.SharedVars.getVehicles()) {
				DoublePoint pos = ClientFunctions.GUI.convertPointToMap(this.type, vehicle.getPosition());
				vehicleImg = new GUIMapVehicle(this.type, vehicle, (vehicle.getObjID() == ClientApp.SharedVars.getMyVehicle().getObjID()));
				g2.drawImage(vehicleImg.getImage(), null, (int) pos.getX() - GUIMapVehicle.g2Whalf, (int) pos.getY() - GUIMapVehicle.g2Hhalf);
			}

			// Projectiles
			for(ProjectileInt projectile : ClientApp.SharedVars.getProjectiles()) {
				DoublePoint pos = ClientFunctions.GUI.convertPointToMap(this.type, projectile.getPosition());
				projectileImg = new GUIMapProjectile(this.type, projectile);
				g2.drawImage(projectileImg.getImage(), null, (int) pos.getX() - GUIMapProjectile.g2Whalf, (int) pos.getY() - GUIMapProjectile.g2Hhalf);
			}

			// Tracks
			for(TrackInt track : ClientApp.SharedVars.getTracks()) {
				DoublePoint pos = ClientFunctions.GUI.convertPointToMap(this.type, track.getPosition());
				trackImg = new GUIMapTrack(this.type, track);
				g2.drawImage(trackImg.getImage(), null, (int) pos.getX() - GUIMapTrack.g2Whalf, (int) pos.getY() - GUIMapTrack.g2Hhalf);
			}
		} catch(Exception e) {}

		// repaint();
	}


}
